package cn.kgc.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.subject.Subject;

/**
 * @author 课工场
 * @date 2024/12/6
 * @description
 */
public class TestCustomerRealm {

    public static void main(String[] args) {


        DefaultSecurityManager securityManager = new DefaultSecurityManager();
        CustomerRealm realm = new CustomerRealm();
        //  设置凭证匹配器  MD5
        HashedCredentialsMatcher md5 = new HashedCredentialsMatcher("MD5");
        // 设置凭证匹配器的hash次数
        md5.setHashIterations(10);
        realm.setCredentialsMatcher(md5);

        securityManager.setRealm(realm);
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        String username = "root";
        String password = "123456";
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
        subject.login(usernamePasswordToken);
        boolean authenticated = subject.isAuthenticated();
        System.out.println("authenticated = " + authenticated);

    }
}
